package com.share.threadmethod;


public class Demo1_Name {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		//demo1();  //构造方法设置名字
		Thread t1 = new Thread() {
			public void run() {
				//this.setName("123");
				System.out.println(this.getName() + "....aaaaaaaaaaaaa");
			}
		};

		Thread t2 = new Thread() {
			public void run() {
				//this.setName("abc");
				System.out.println(super.getName() + "....bb");
			}
		};

		Thread t3 = new Thread(new Runnable() {
			public void run() {
				Thread.currentThread().setName("sunxj");        //无法用this，因为Runnable没有getname方法，只能通过获取当前对象
				System.out.println(Thread.currentThread().getName() +"======");

			}
		});

//		t1.setName("123");
//		t2.setName("abc");
//		t3.setName("sunxj");
//		
		
		t1.start();
		t2.start();
		t3.start();

	}

	public static void demo1() {
		new Thread("123") {							//通过构造方法给name赋值
			public void run() {
				this.setName("abc");                 //run中重新赋值
				System.out.println(this.getName() + "....aaaaaaaaa");
			}
		}.start();

		new Thread("456") {
			public void run() {
				this.setName("def");
				System.out.println(this.getName() + "....bb");
			}
		}.start();
	}

}
